/*
 * Copyright (c) 2018-2028 兰州安众信息科技有限公司 All Rights Reserved.
 * ProjectName: 甘肃九建OA系统
 */

package com.book.manager.base.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

/**
 * <p>
 *  返回结果封装
 * </p>
 *
 * @author panzc
 * @since 2020-01-17
 */
@ApiModel(value = "返回类")
public class BaseResult<T> implements Serializable {

    private static final long serialVersionUID = 3055500232134711804L;
    @ApiModelProperty(value = "code,0:成功，非0:失败")
    private Integer code;

    @ApiModelProperty(value = "描述")
    private String message;

    @ApiModelProperty(value = "返回对象")
    private T data;

    protected BaseResult() {
        super();
        this.code = null;
        this.message = null;
        this.data = null;
    }
    protected BaseResult(CodeMsg codeMsg) {
        super();
        this.code = codeMsg.getCode();
        this.message = codeMsg.getMessage();
        this.data = null;
    }

    protected BaseResult(CodeMsg codeMsg,T data) {
        super();
        this.code = codeMsg.getCode();
        this.message = codeMsg.getMessage();
        this.data = data;
    }

    public BaseResult(String message) {
        this.code = CodeMsgEnum.FAILED.getCode();
        this.message = message;
        this.data = null;
    }

    public static BaseResult of(CodeMsg codeMsg) {
        return new BaseResult(codeMsg);
    }
    public static <T> T of(T data) {
        return data;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
    public void setCode(Integer code) {
        this.code = code;
    }
    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}